/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package estates;

import com.sun.webui.jsf.component.DropDown;
import com.sun.webui.jsf.model.SingleSelectOptionsList;
import estates.model.Estate;
import com.sun.data.provider.impl.ObjectListDataProvider;
import com.sun.webui.jsf.component.Tab;
import com.sun.webui.jsf.component.TabSet;
import com.sun.webui.jsf.component.Table;
import com.sun.webui.jsf.component.TableRowGroup;
import com.sun.webui.jsf.component.TextField;
// estates.offer.*;
import com.sun.webui.jsf.model.DefaultTableDataProvider;
import estates.validation.*;

import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.StaticText;
import estates.util.ErrorCodes;
import estates.util.ParamGenerator;
import estates.util.TransferEstate;
import estates.util.TransferUser;
import javax.faces.FacesException;
import javax.faces.validator.LongRangeValidator;

/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @version szczegoly.java
 * @version Created on 2011-05-15, 13:31:18
 * @author Karol
 */

public class szczegoly extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }
    private StaticText s_miasto = new StaticText();

    public StaticText getS_miasto() {
        return s_miasto;
    }

    public void setS_miasto(StaticText st) {
        this.s_miasto = st;
    }

    private Estate e = null; //this.getApplicationBean1().getFasada().getOferta(this.getRequestBean1().getOferta());

    public Estate getE() {
        return e;
    }

    public void setE(Estate e) {
        this.e = e;
    }
    private StaticText s_dzielnica = new StaticText();

    public StaticText getS_dzielnica() {
        return s_dzielnica;
    }

    public void setS_dzielnica(StaticText st) {
        this.s_dzielnica = st;
    }
    private StaticText s_adres = new StaticText();

    public StaticText getS_adres() {
        return s_adres;
    }

    public void setS_adres(StaticText st) {
        this.s_adres = st;
    }
    private StaticText s_metraz = new StaticText();

    public StaticText getS_metraz() {
        return s_metraz;
    }

    public void setS_metraz(StaticText st) {
        this.s_metraz = st;
    }
    private StaticText s_cena = new StaticText();

    public StaticText getS_cena() {
        return s_cena;
    }

    public void setS_cena(StaticText st) {
        this.s_cena = st;
    }
    private StaticText s_zabudowa = new StaticText();

    public StaticText getS_zabudowa() {
        return s_zabudowa;
    }

    public void setS_zabudowa(StaticText st) {
        this.s_zabudowa = st;
    }
    private StaticText s_stan = new StaticText();

    public StaticText getS_stan() {
        return s_stan;
    }

    public void setS_stan(StaticText st) {
        this.s_stan = st;
    }
    private StaticText s_opis = new StaticText();

    public StaticText getS_opis() {
        return s_opis;
    }

    public void setS_opis(StaticText st) {
        this.s_opis = st;
    }
    private TextField textField1 = new TextField();

    public TextField getTextField1() {
        return textField1;
    }

    public void setTextField1(TextField tf) {
        this.textField1 = tf;
    }
    private LongRangeValidator longRangeValidator1 = new LongRangeValidator();

    public LongRangeValidator getLongRangeValidator1() {
        return longRangeValidator1;
    }

    public void setLongRangeValidator1(LongRangeValidator lrv) {
        this.longRangeValidator1 = lrv;
    }


    // </editor-fold>

    CommentValidator commentValidator = new CommentValidator(500);

    public CommentValidator getCommentValidator() {
        return commentValidator;
    }

    public void setCommentValidator(CommentValidator commentValidator) {
        this.commentValidator = commentValidator;
    }
    private ObjectListDataProvider objectListDataProvider1 = new ObjectListDataProvider(this.getApplicationBean1().getEstateCommentsStringList(this.getSessionBean1().getShowestate()));

    public ObjectListDataProvider getObjectListDataProvider1() {
        return objectListDataProvider1;
    }

    public void setObjectListDataProvider1(ObjectListDataProvider oldp) {
        this.objectListDataProvider1 = oldp;
    }
    private DefaultTableDataProvider defaultTableDataProvider = new DefaultTableDataProvider();

    public DefaultTableDataProvider getDefaultTableDataProvider() {
        return defaultTableDataProvider;
    }

    public void setDefaultTableDataProvider(DefaultTableDataProvider dtdp) {
        this.defaultTableDataProvider = dtdp;
    }
    private Table table1 = new Table();

    public Table getTable1() {
        return table1;
    }

    public void setTable1(Table t) {
        this.table1 = t;
    }
    private TableRowGroup tableRowGroup1 = new TableRowGroup();

    public TableRowGroup getTableRowGroup1() {
        return tableRowGroup1;
    }

    public void setTableRowGroup1(TableRowGroup trg) {
        this.tableRowGroup1 = trg;
    }


    TransferEstate te = new TransferEstate();
    TransferUser tu = new TransferUser();

    private boolean showOfertaTab = true;
    private boolean showBudynekTab = true;
    private boolean showLokalTab = false;

    public boolean isShowBudynekTab() {
        return showBudynekTab;
    }

    public void setShowBudynekTab(boolean showBudynekTab) {
        this.showBudynekTab = showBudynekTab;
    }

    public boolean isShowLokalTab() {
        return showLokalTab;
    }

    public void setShowLokalTab(boolean showLokalTab) {
        this.showLokalTab = showLokalTab;
    }

    public boolean isShowOfertaTab() {
        return showOfertaTab;
    }

    public void setShowOfertaTab(boolean showOfertaTab) {
        this.showOfertaTab = showOfertaTab;
    }

    public TransferEstate getTe() {
        return te;
    }

    public void setTe(TransferEstate te) {
        this.te = te;
    }
    private TabSet tabSet1 = new TabSet();

    public TabSet getTabSet1() {
        return tabSet1;
    }

    public void setTabSet1(TabSet ts) {
        this.tabSet1 = ts;
    }
    private Tab tab1 = new Tab();

    public Tab getTab1() {
        return tab1;
    }

    public void setTab1(Tab t) {
        this.tab1 = t;
    }
    private Tab tab2 = new Tab();

    public Tab getTab2() {
        return tab2;
    }

    public void setTab2(Tab t) {
        this.tab2 = t;
    }
    private Tab tab3 = new Tab();

    public Tab getTab3() {
        return tab3;
    }

    public void setTab3(Tab t) {
        this.tab3 = t;
    }
    private StaticText show_numer_oferty = new StaticText();

    public StaticText getShow_numer_oferty() {
        return show_numer_oferty;
    }

    public void setShow_numer_oferty(StaticText st) {
        this.show_numer_oferty = st;
    }
    private StaticText show_wojewodztwo = new StaticText();

    public StaticText getShow_wojewodztwo() {
        return show_wojewodztwo;
    }

    public void setShow_wojewodztwo(StaticText st) {
        this.show_wojewodztwo = st;
    }
    private StaticText show_opis = new StaticText();

    public StaticText getShow_opis() {
        return show_opis;
    }

    public void setShow_opis(StaticText st) {
        this.show_opis = st;
    }
    private StaticText show_cena = new StaticText();

    public StaticText getShow_cena() {
        return show_cena;
    }

    public TransferUser getTu() {
        return tu;
    }

    public void setTu(TransferUser tu) {
        this.tu = tu;
    }



    public void setShow_cena(StaticText st) {
        this.show_cena = st;
    }
    private StaticText show_miejscowosc = new StaticText();

    public StaticText getShow_miejscowosc() {
        return show_miejscowosc;
    }

    public void setShow_miejscowosc(StaticText st) {
        this.show_miejscowosc = st;
    }
    private StaticText show_powierzchnia = new StaticText();

    public StaticText getShow_powierzchnia() {
        return show_powierzchnia;
    }

    public void setShow_powierzchnia(StaticText st) {
        this.show_powierzchnia = st;
    }
    private StaticText show_rok_budowy = new StaticText();

    public StaticText getShow_rok_budowy() {
        return show_rok_budowy;
    }

    public void setShow_rok_budowy(StaticText st) {
        this.show_rok_budowy = st;
    }
    private StaticText show_stan_prawny = new StaticText();

    public StaticText getShow_stan_prawny() {
        return show_stan_prawny;
    }

    public void setShow_stan_prawny(StaticText st) {
        this.show_stan_prawny = st;
    }
    private StaticText show_numer_budynku = new StaticText();

    public StaticText getShow_numer_budynku() {
        return show_numer_budynku;
    }

    public void setShow_numer_budynku(StaticText st) {
        this.show_numer_budynku = st;
    }
    private StaticText show_pietra = new StaticText();

    public StaticText getShow_pietra() {
        return show_pietra;
    }

    public void setShow_pietra(StaticText st) {
        this.show_pietra = st;
    }
    private StaticText show_pokoje = new StaticText();

    public StaticText getShow_pokoje() {
        return show_pokoje;
    }

    public void setShow_pokoje(StaticText st) {
        this.show_pokoje = st;
    }
    private StaticText show_kod_pocztowy = new StaticText();

    public StaticText getShow_kod_pocztowy() {
        return show_kod_pocztowy;
    }

    public void setShow_kod_pocztowy(StaticText st) {
        this.show_kod_pocztowy = st;
    }
    private StaticText show_ulica = new StaticText();

    public StaticText getShow_ulica() {
        return show_ulica;
    }

    public void setShow_ulica(StaticText st) {
        this.show_ulica = st;
    }
    private StaticText show_typ_lokalu = new StaticText();

    public StaticText getShow_typ_lokalu() {
        return show_typ_lokalu;
    }

    public void setShow_typ_lokalu(StaticText st) {
        this.show_typ_lokalu = st;
    }
    private StaticText show_liczba_lazienek = new StaticText();

    public StaticText getShow_liczba_lazienek() {
        return show_liczba_lazienek;
    }

    public void setShow_liczba_lazienek(StaticText st) {
        this.show_liczba_lazienek = st;
    }
    private StaticText show_numer_lokalu = new StaticText();

    public StaticText getShow_numer_lokalu() {
        return show_numer_lokalu;
    }

    public void setShow_numer_lokalu(StaticText st) {
        this.show_numer_lokalu = st;
    }
    private StaticText show_pietro = new StaticText();

    public StaticText getShow_pietro() {
        return show_pietro;
    }

    public void setShow_pietro(StaticText st) {
        this.show_pietro = st;
    }
    private StaticText show_rozkladowy = new StaticText();

    public StaticText getShow_rozkladowy() {
        return show_rozkladowy;
    }

    public void setShow_rozkladowy(StaticText st) {
        this.show_rozkladowy = st;
    }
    private StaticText staticText3 = new StaticText();

    public StaticText getStaticText3() {
        return staticText3;
    }

    public void setStaticText3(StaticText st) {
        this.staticText3 = st;
    }
    private StaticText sr_komfort = new StaticText();

    public StaticText getSr_komfort() {
        return sr_komfort;
    }

    public void setSr_komfort(StaticText st) {
        this.sr_komfort = st;
    }
    private StaticText sr_lokalizacja = new StaticText();

    public StaticText getSr_lokalizacja() {
        return sr_lokalizacja;
    }

    public void setSr_lokalizacja(StaticText st) {
        this.sr_lokalizacja = st;
    }
    private StaticText sr_estetyka = new StaticText();

    public StaticText getSr_estetyka() {
        return sr_estetyka;
    }

    public void setSr_estetyka(StaticText st) {
        this.sr_estetyka = st;
    }
    private DropDown dropDown1 = new DropDown();

    public DropDown getDropDown1() {
        return dropDown1;
    }

    public void setDropDown1(DropDown dd) {
        this.dropDown1 = dd;
    }

    

    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public szczegoly() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        Estate tmp = this.getApplicationBean1().getFasada().Szukaj_estate(this.getSessionBean1().getShowestate());
        if(tmp!=null){
            te = new TransferEstate(tmp.toString());
            tu = new TransferUser(this.getApplicationBean1().getFasada().Szukaj_user(te.getUser()).toString());
        }
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
        objectListDataProvider1 = new ObjectListDataProvider(this.getApplicationBean1().getFasada().getEstatesComments(te.getNumer_oferty()));
        
        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("szczegoly Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
        showLokalTab = te.getTypOferty().equals("OfertaLokalowa");
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    public String button1_action() {
        this.getSessionBean1().setShowestate(te.getNumer_oferty());
        this.getRequestBean1().setOferta(te.getNumer_oferty());
        this.getRequestBean1().setUzytkownik(tu.getNip());
        return "uinfo";
    }

    public String button2_action() {
        String est = this.getSessionBean1().getShowestate();
        String user = ParamGenerator.ConvertSelection(dropDown1).toString();

        int result = this.getApplicationBean1().getFasada().dodajDoObserwowanych(est, user);

        if(result == ErrorCodes.OBS_OK){
            this.getRequestBean1().setKomunikat("Pomyślnie dodano ofertę do obserwowanych");
            this.getRequestBean1().setNapis("Powrót do danych oferty");
            this.getSessionBean1().setLink("szczegoly");
            return "sukces";
        }else{
            this.getRequestBean1().setKomunikat("Dodanie oferty do obserwowanych zakończone niepowodzeniem");
            return "blad";
        }
    }

    public String button3_action() {
        String est = this.getSessionBean1().getShowestate();
        String user = ParamGenerator.ConvertSelection(dropDown1).toString();

        int result = this.getApplicationBean1().getFasada().usunZobserwowanych(est, user);

        if(result == ErrorCodes.OBS_OK){
            this.getRequestBean1().setKomunikat("Pomyślnie usunięto ofertę z obserwowanych");
            this.getRequestBean1().setNapis("Powrót do danych oferty");
            this.getSessionBean1().setLink("szczegoly");
            return "sukces";
        }else{
            this.getRequestBean1().setKomunikat("Nie znaleziono na liście");
            return "blad";
        }
    }

    
}

